package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.ClassBean;
import com.project.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("Class")//别名自己取
//类名记着自己改一下
public class ClassController {
    @Autowired
    private IClassService service;

    @RequestMapping("findAll")
    public String findAll(@RequestParam(value = "pageNO",defaultValue = "1") int pageNO, HttpServletRequest request){
        PageInfo<ClassBean> pageInfo=service.findAll(pageNO);
        request.setAttribute("pageInfo",pageInfo);
        return "html/Class/index.html";
    }

    @RequestMapping("del")
    public String del(int id){
        service.del(id);
        return "redirect:/Class/findAll";
    }

    @RequestMapping("findById")
    public String findById(int id,HttpServletRequest request){
        ClassBean classBean=service.findById(id);
        request.setAttribute("classBean",classBean);
        return "html/Class/update.html";
    }

    @RequestMapping("update")
    public String update(int id,String teacherName){
        service.update(id,teacherName);
        return "redirect:/Class/findAll";
    }

    @RequestMapping("add")
    public String add(ClassBean classBean){
        service.add(classBean);
        return "redirect:/Class/findAll";
    }
}